#@layoutUser()
#define mainUser()

<div style="float: right;width: 960px">
   	<fieldset class="layui-elem-field layui-field-title">
	  <legend>资源管理</legend>
	</fieldset>
    <div>
	    <div>
	    	 <div style="padding: 20px">
	          	<div class="layui-form">
		          <div class="layui-inline">
		            <label class="layui-form-label">资源名称：</label>
		            <div class="layui-input-inline">
		              <input type="text" id="s_name" style="width: 300px" placeholder="请输入" autocomplete="off" class="layui-input" onkeydown="if(event.keyCode==13) search()">
		            </div>
		          </div>
		          
		          <div class="layui-inline">
		              <label class="layui-form-label">审核状态：</label>
			          <div class="layui-input-inline">
					      <select id="s_state" name="s_state">
					        <option value="">请选择审核状态</option>
					        <option value="1">未审核</option>
					        <option value="2">审核通过</option>
					        <option value="3">审核未通过</option>
					      </select>
					    </div>
		            </div>
					&nbsp;&nbsp;
		          <div class="layui-inline">
		            <button class="layui-btn layuiadmin-btn-list" lay-submit="" onclick="search()" lay-filter="LAY-app-contlist-search">
		              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
		            </button>
		          </div>
		        </div>
	          </div>
	    	<div>
	          <button class="layui-btn layuiadmin-btn-list" data-type="add" onclick="window.location.href='/user/userArticleWrite'">发布资源</button>
	          &nbsp;&nbsp;(&nbsp;<font color="red">1，鼠标移动到红色“审核未通过”字体上，能显示未通过原因；2，审核未通过的，请重新编辑帖子，然后提交审核；</font>&nbsp;)
	    	</div>
	    </div>
	    <div>
	   		<table class="layui-hide" id="articleListTable"></table>
	    </div>
	</div>
</div>

#end

#define js()

<script>
/*<![CDATA[*/  
layui.use(['element','form','table'], function(){
    var form=layui.form;
	  var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
	  $ = layui.jquery; // 使用jquery
	  table = layui.table;
	  
	  table.render({
	    elem: '#articleListTable'
	    ,url:'/article/articleListTable'
	    ,id:'articleList'
	    ,cols: [[
			{field:'aid', width:80, title: '编号', sort: true,align:'center'}
	      ,{field:'name', width:330, title: '资源名称',templet:formatName}
	      ,{field:'typeName', width:100, title: '所属类别'}
	      ,{field:'points', width:80, title: '积分',align:'center',sort: true}
	      ,{field:'publish_date', width:120, title: '发布日期', sort: true,align:'center'}
	      ,{field:'state', width:100, title: '审核状态',align:'center',templet:formatState}
	      ,{field:'action', width:150, title: '操作',align:'center',templet:formatAction}
	    ]]
	    ,page: true
	  }); 
});

function search(){
	var s_name=$("#s_name").val();
	var s_state=$("#s_state").val();
	//alert(s_state);
	table.reload("articleList",{
		page:{
			curr:1
		}
		,where:{
			name:s_name,
			state:s_state
		}
	});
}

//审核的状态
function formatState(d){
	if(d.state==1){
		return "未审核";
	}else if(d.state==2){
		return "<font color=blue>审核通过</font>";
	}else if(d.state==3){
		return "<a href='#' title='审核未通过原因："+d.reason+"''><font color=red>审核未通过</font></a><br/>";
	}
}
//文章标题跳转
function formatName(d){
	if(d.state==2){
		return "<a href='/article/"+d.aid+"' target='_blank'>"+d.name+"</a>";
	}else{
		return d.name;
	}
}
//删除一个文章
function deleteOne(aid){
	layer.confirm('您确定要删除这条记录吗？', {
     title:"系统提示"
	  ,btn: ['确定','取消'] //按钮
	}, function(){
		layer.closeAll('dialog');
		window.location.href="/article/deleteArticle/"+aid;
	}, function(){
	 
	});

}

//编辑一个文章
function modifyArticle(aid){
	//layer.alert("11");
	window.location.href="/article/toModifyArticlePage/"+aid;
}

//文章右侧的操作
function formatAction(d){
	return "<button class='layui-btn layui-btn-normal layui-btn-xs' onclick='modifyArticle("+d.aid+")'><i class='layui-icon layui-icon-edit'></i>编辑</button><button class='layui-btn layui-btn-warm layui-btn-xs' onclick='deleteOne("+d.aid+")'><i class='layui-icon layui-icon-delete' ></i>删除</button>";
}

/*]]>*/
</script>

#end